package is95powercontrol;

import javafx.scene.shape.Path;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.HLineTo;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.VLineTo;
import javafx.scene.shape.Circle;
import javafx.animation.Interpolator;
import javafx.animation.Timeline;
import javafx.animation.transition.AnimationPath;
import javafx.animation.transition.OrientationType;
import javafx.animation.transition.PathTransition;
import javafx.scene.input.MouseEvent;
import javafx.stage.Screen;
import java.lang.Void;
import javafx.scene.text.Font;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TextBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.scene.control.Label;
import javafx.animation.KeyFrame;

/**
 * @author Andrzej
 */



def path: Path = Path {
    strokeWidth: 1
    stroke: Color.RED
    strokeDashArray: [2, 5]
    elements: [
        MoveTo  { x:  250 y: 250 }
        VLineTo { y:  290 }
        LineTo  { x:  210 y: 250 }
        ArcTo   { x:  290 y: 250 radiusX: 30 radiusY: 30 sweepFlag: true }
        ArcTo   { x:  190 y: 250 radiusX: 50 radiusY: 50 sweepFlag: true }
        ArcTo   { x:  330 y: 250 radiusX: 60 radiusY: 60 sweepFlag: true }
        ArcTo   { x:  170 y: 250 radiusX: 70 radiusY: 70 sweepFlag: true }
        ArcTo   { x:  350 y: 250 radiusX: 80 radiusY: 80 sweepFlag: true }
        ArcTo   { x:  150 y: 250 radiusX: 90 radiusY: 90 sweepFlag: true }
        ArcTo   { x:  370 y: 250 radiusX: 100 radiusY: 100 sweepFlag: true }
        ArcTo   { x:  130 y: 250 radiusX: 110 radiusY: 110 sweepFlag: true }
        ArcTo   { x:  390 y: 250 radiusX: 120 radiusY: 120 sweepFlag: true }
        ArcTo   { x:  110 y: 250 radiusX: 130 radiusY: 130 sweepFlag: true }
        ArcTo   { x:  410 y: 250 radiusX: 140 radiusY: 140 sweepFlag: true }
        ArcTo   { x:  90  y: 250 radiusX: 150 radiusY: 150 sweepFlag: true }
        ArcTo   { x:  430 y: 250 radiusX: 160 radiusY: 160 sweepFlag: true }
        ArcTo   { x:  70  y: 250 radiusX: 170 radiusY: 170 sweepFlag: true }
        ArcTo   { x:  450 y: 250 radiusX: 180 radiusY: 180 sweepFlag: true }
        HLineTo { x:  250}
        ClosePath {}
    ]
}

var gBaseStation = Circle {
    centerX: 250,
    centerY: 250,
    radius: 8,
    fill: Color.RED
}

var gMobileStation = Rectangle {
    x: 258,
    y: 258,
    width: 5,
    height: 10,
    fill: Color.GREEN
    smooth: true
}

var pathTrans = PathTransition {
    node: gMobileStation
    path: AnimationPath.createFromPath(path)
    orientation: OrientationType.ORTHOGONAL_TO_TANGENT
    interpolator: Interpolator.LINEAR
    duration: 70s
    repeatCount: Timeline.INDEFINITE
    rate: 1.0
}

var circleLabel = Label {
    translateX: bind Screen.primary.visualBounds.minX + 60
    translateY: bind Screen.primary.visualBounds.minY + 10
    font: Font{
        name: "Times New Roman"
        size: 20
    }
    text: "Ruch MS wzgledem BTS [Promien komorki = 8000 m]"
}

var circle = Circle {
	centerX: 250
	centerY: 250
	radius: 200
        stroke: Color.GREEN
	fill: Color.WHITE
	onMouseClicked: function( e: MouseEvent ): Void {
	  if (pathTrans.paused == false)
	  {
	  	pathTrans.pause();
	  	time_line.pause();;
	  }
	  else
	  {
		pathTrans.play();
		time_line.play();		
	  }
	}
        smooth: false
}

var celluar = Group {
    translateX: bind Screen.primary.visualBounds.minX + 10
    translateY: bind Screen.primary.visualBounds.minY + 10
    content: [
        circleLabel,
        circle,
        path,
        gBaseStation,
        gMobileStation,
    ]
}

var pilotMonitor = PilotMonitor {
    mobileStationX: gMobileStation.translateX
    mobileStationY: gMobileStation.translateY
    x: Screen.primary.visualBounds.maxX - 500
    y: Screen.primary.visualBounds.minY
    height: 280
    width: 450
    visible: false
  };

var transmisionMonitor = TransmisionMonitor {
    height: 280
    width: 450
    x: Screen.primary.visualBounds.maxX - 500
    y: Screen.primary.visualBounds.minY + 300
    visible: false
}

var chartGroup = Group {
    content: [
            pilotMonitor,
            transmisionMonitor
    ]
}

var commandLabel = Label {
    font: Font{
        name: "Times New Roman"
        size: 20
    }
    text: "  Wymiana informacji sterowania moca [BTS -> Mobile]"
}

var textRectangle = Rectangle{
                x: commandLabel.translateX + 40
                y: commandLabel.translateY + 40
                width: 400
                height: 200
                fill: Color.web("#1F6592")
                opacity: 0.4
}

var textAreaMonitor = TextAreaMonitor {
    mobX: bind gMobileStation.layoutX;
    x: bind textRectangle.x + 30
    y: bind textRectangle.y + 20
    wrapWidth: bind textRectangle.width*0.8

}

var textGroup = Group {
	content: [
            commandLabel,
            textRectangle,
            textAreaMonitor
	]
}


var connectedLabel = Label {
    font: Font{
        name: "Times New Roman"
        size: 20
    }
    text: "Podlaczony: "
}

var connectedBox = TextBox {
        height: 30
	text: "TAK"
	columns: 12
        editable: true;
}

var distanceLabel = Label {
    font: Font{
        name: "Times New Roman"
        size: 20
    }
    text: "Odleglosc MS od BTS [km]: "
}

var distanceBox = TextBox {
        height: 30
	text: "{200}"
	columns: 12
        editable: true;
}

var pilotPwrLabel = Label {
    font: Font{
        name: "Times New Roman"
        size: 20
    }
    text: "Moc pilota z BTS [dBm]: "
}

var pilotPwrBox = TextBox {
        height: 30
	text: "{200}"
	columns: 12
        editable: true;
}

var mobilePwrLabel = Label {
    font: Font{
        name: "Times New Roman"
        size: 20
    }
    text: "Moc sygnalu z Mobile [dBm]: "
}

var mobilePwrBox = TextBox {
        height: 30
	text: "{200}"
	columns: 12
        editable: true;
}

var time_line = Timeline {

        repeatCount: Timeline.INDEFINITE
        keyFrames: KeyFrame {
                    time: 100ms
                    action: function(){
                        pilotMonitor.updatePilot();
                        transmisionMonitor.updateTransmision();                        
                        textAreaMonitor.updateTextArea(gMobileStation.translateX, gMobileStation.translateY);
                    }
        }
}

time_line.play();


Stage {
title : "IS95PowerControl"
  //  x: Screen.primary.visualBounds.minX
  //  y: Screen.primary.visualBounds.minY
    width: Screen.primary.visualBounds.width
    height: Screen.primary.visualBounds.height
scene: Scene {
//    width: Screen.primary.visualBounds.width
//    height: Screen.primary.visualBounds.height
    content: [
       HBox {

        spacing: 80;
        content: [
            VBox {
                spacing: 20
                width: bind Screen.primary.visualBounds.maxX*0.4
                content : [
                    celluar,
                    textGroup
                ]
            }
            VBox {
                spacing: 20
                width: bind Screen.primary.visualBounds.maxX*0.2
                content : [
                    connectedLabel,
                    connectedBox,
                    distanceLabel,
                    distanceBox,
                    pilotPwrLabel,
                    pilotPwrBox,
                    mobilePwrLabel,
                    mobilePwrBox
                ]
            }
            VBox {
                spacing: 20
                width: bind Screen.primary.visualBounds.maxX*0.4
                content : [
                    pilotMonitor,
                    transmisionMonitor
                ]
            }

        ]
	}
 


      ]
    }
}    

     pilotMonitor.visible = true;
     transmisionMonitor.visible = true;
     textAreaMonitor.visible = true;
     pathTrans.play();